#!/usr/bin/env python3 
# -*- coding: UTF-8 -*-

'''
测试百度首页
by lina
'''
from src.gui.page import base_page

class BaiduIndex(base_page.BasePage):

	def __init__(self):
		super().__init__()
		self.index_url = 'https://www.baidu.com/'


	"""
	进入当前页面
	by lina
	"""
	def in_this_page(self):
		self.mlog.add_log('BaiduIndex','in_this_page','进入百度首页')
		self.driver.get(self.index_url)
		self.mscreenshot.add_screenshot(self.driver,'baidu_index')

	"""
	刷新当前页面
	by lina
	"""
	def refresh_page(self):
		self.mlog.add_log('BaiduIndex','refresh_page','刷新百度首页')
		self.driver.refresh

	"""
	搜索功能测试
	content:搜索的内容
	by lina
	"""
	def search_content(self,content):
		self.mlog.add_log('BaiduIndex','seach_content','清空输入栏')
		self.driver.find_element_by_xpath("//input[@id='kw']").clear()
		self.mlog.add_log('BaiduIndex','seach_content','输入要搜索的内容:'+content)
		self.driver.find_element_by_xpath("//input[@id='kw']").send_keys(content)
		super().delay_time()
		self.mlog.add_log('BaiduIndex','seach_content','提交搜索')
		self.mscreenshot.add_screenshot(self.driver,'baidu_search')
		self.driver.find_element_by_xpath("//input[@id='su']").click()
		super().delay_time()

	"""
	跳转链接
	page_name:要跳转的连接的名称
	by lina
	"""
	def link_to_page(self,page_name):
		
		if page_name == '新闻':
			xpath_name = 'tj_trnews'
		elif page_name == '地图':
			xpath_name = 'tj_trmap'
		elif page_name == '学术':
			xpath_name = 'tj_trxueshu'
		else:
			xpath_name = ''

		self.mlog.add_log('BaiduIndex','link_to_page','通过链接进入'+page_name+'页面')
		self.driver.find_element_by_xpath("//a[@name='"+xpath_name+"']").click() 
		super().delay_time()

